home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_oth / m2cmp20 / inout.def < prev    next >
Text File  |  1988-11-19  |  5KB  |  187 lines

  1. DEFINITION MODULE InOut;
  2.  
  3. (* (C) Copyright 1987,1988 Fitted Software Tools. All rights reserved. *)
  4.  
  5. (*
  6.     This is the standard module InOut as defined in
  7.     "Programming in Modula-2" by Niklaus Wirth.
  8.  
  9.     A few additionns were made to this modules, mainly
  10.     to add support for LONGINT and LONGCARD data types
  11. *)
  12.  
  13. FROM SYSTEM     IMPORT WORD;
  14. FROM FileSystem IMPORT File;
  15.  
  16. CONST
  17.     EOL = 36C;
  18.  
  19. VAR
  20.     Done    :BOOLEAN;
  21.     termCH  :CHAR;
  22.  
  23. (*
  24.     Done is set by the procedures
  25.         OpenInput, OpenOutput,
  26.         RedirectInput, RedirectOutput,
  27.         Read, ReadInt, ReadCard,
  28.         ReadLongInt, ReadLongCard,
  29.         ReadWrd, WriteWrd,
  30.     to indicate if the call was successful or not.
  31. *)
  32.  
  33.  
  34. PROCEDURE OpenInput( defext :ARRAY OF CHAR );
  35. (*
  36.     prompts the user for a file to redirect the input from.
  37.     if the last character in the input is a '.', defext is
  38.     appended to it.
  39. *)
  40.  
  41. PROCEDURE OpenOutput( defext :ARRAY OF CHAR );
  42. (*
  43.     prompts the user for a file to redirect the input to.
  44.     if the last character in the input is a '.', defext is
  45.     appended to it.
  46. *)
  47.  
  48. PROCEDURE RedirectInput( from :ARRAY OF CHAR );
  49. (*
  50.     redirects the input from file from.
  51. *)
  52.  
  53. PROCEDURE RedirectOutput( to :ARRAY OF CHAR );
  54. (*
  55.     redirects the output to file to.
  56. *)
  57.  
  58. PROCEDURE CloseInput;
  59. (*
  60.     the file opened with OpenInput or RedirectInput is closed
  61.     and the terminal is reestablished as the input device.
  62. *)
  63.  
  64. PROCEDURE CloseOutput;
  65. (*
  66.     the file opened with OpenOutput or RedirectOutput is closed
  67.     and the terminal is reestablished as the output device.
  68. *)
  69.  
  70. PROCEDURE Read( VAR ch :CHAR );
  71. (*
  72.     read a character
  73. *)
  74.  
  75. PROCEDURE ReadString( VAR s :ARRAY OF CHAR );
  76. (*
  77.     read a string.
  78.     input is terminated by a ' ', or any control character except BS or DEL.
  79.     the terminating character is saved in termCH.
  80.     when reading from the terminal, editing of the input is available:
  81.         ASCII.BS deletes the last characted input
  82.         ASCII.DEL deletes all characters input
  83.         ASCII.ESC deletes all characters input and returns
  84. *)
  85.  
  86. PROCEDURE ReadLine( VAR s :ARRAY OF CHAR );
  87. (*
  88.     read a line.
  89.     input is terminated by an EOL, EOF or ESC character.
  90.     the terminating character is saved in termCH.
  91.     when reading from the terminal, editing of the input is available:
  92.         ASCII.BS deletes the last characted input
  93.         ASCII.DEL deletes all characters input
  94.         ASCII.ESC deletes all characters input and returns
  95. *)
  96.  
  97. PROCEDURE ReadInt( VAR x :INTEGER );
  98. (*
  99.     a string is read from the input device and is then converted to
  100.     an INTEGER.
  101. *)
  102.  
  103. PROCEDURE ReadCard( VAR x :CARDINAL );
  104. (*
  105.     a string is read from the input device and is then converted to
  106.     a CARDINAL.
  107. *)
  108.  
  109. PROCEDURE ReadWrd( VAR w :WORD );
  110. (*
  111.     read a WORD from the input file.
  112.     legal only if input is being redirected from a file.
  113. *)
  114.  
  115. PROCEDURE Write( ch :CHAR );
  116. (*
  117.     write the character
  118. *)
  119.  
  120. PROCEDURE WriteLn;
  121. (*
  122.     same as: Write( ASCII.EOL )
  123. *)
  124.  
  125. PROCEDURE WriteString( s :ARRAY OF CHAR );
  126. (*
  127.     write the string out
  128. *)
  129.  
  130. PROCEDURE WriteLine( s :ARRAY OF CHAR );
  131. (*
  132.     same as: WriteString( s ); WriteLn;
  133. *)
  134.  
  135. PROCEDURE WriteInt( x :INTEGER; n :CARDINAL );
  136. (*
  137.     write the INTEGER right justified in a field of at least n characters.
  138. *)
  139.  
  140. PROCEDURE WriteCard( x, n :CARDINAL );
  141. (*
  142.     write the CARDINAL right justified in a field of at least n characters.
  143. *)
  144.  
  145. PROCEDURE WriteOct( x, n :CARDINAL );
  146. (*
  147.     write x in octal format in a right justified field of at least n characters.
  148.     IF (n <= 3) AND (x < 100H) THEN 3 digits are written
  149.     ELSE 6 digits are written
  150. *)
  151.  
  152. PROCEDURE WriteHex( x, n :CARDINAL );
  153. (*
  154.     write x in hexadecimal in a right justified field of at least n characters.
  155.     IF (n <= 2) AND (x < 100H) THEN 2 digits are written
  156.     ELSE 4 digits are written
  157. *)
  158.  
  159. PROCEDURE WriteWrd( w :WORD );
  160. (*
  161.     write w to the output file.
  162.     only legal when output is being redirected to a file.
  163. *)
  164.  
  165. PROCEDURE ReadLongInt( VAR x :LONGINT );
  166. (*
  167.     a string is read from the input device and is then converted to
  168.     a LONGINT.
  169. *)
  170.  
  171. PROCEDURE ReadLongCard( VAR x :LONGCARD );
  172. (*
  173.     a string is read from the input device and is then converted to
  174.     a LONGCARD.
  175. *)
  176.  
  177. PROCEDURE WriteLongInt( x :LONGINT; n :CARDINAL );
  178. (*
  179.     write the LONGINT right justified in a field of at least n characters.
  180. *)
  181.  
  182. PROCEDURE WriteLongCard( x :LONGCARD; n :CARDINAL );
  183. (*
  184.     write the LONGCARD right justified in a field of at least n characters.
  185. *)
  186.  
  187. END InOut.